package com.example.dell.myapplication;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

/**
 * Created by dell on 2016/9/1.
 */
public class ZiDingYi extends LinearLayout {

    private EditText ed;
    private ImageButton iv;
    public ZiDingYi(Context context) {
        super(context);
    }

    public ZiDingYi(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.my,this,true);
        ed=(EditText) findViewById(R.id.ed);
        iv=(ImageButton) findViewById(R.id.b);
        ed.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (ed.length()==0){
                    iv.setVisibility(View.INVISIBLE);
                }else {
                    iv.setVisibility(View.VISIBLE);
                }
            }
        });
        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ed.setText("");
                iv.setVisibility(View.INVISIBLE);
            }
        });
    }

}
